package BasicClient;

import java.util.HashMap;
import java.util.Observable;
import java.util.Observer;

public abstract class AI implements Observer {
	
	protected AbstractClient client;
	protected HandState handState;
	
	public AI(AbstractClient client){
		this.client = client;
		client.addObserver(this);
	}
	
	@Override
	public void update(Observable observable, Object eventType) {
		EventType type = (EventType) eventType; 
		switch(type){
			case BlindUpdate:
				eventBlindUpdate();
				break;
			case OrderUpdate:
				eventOrderUpdate();
			case HoleCards:
				this.handState = HandState.PREFLOP;
				eventDealtHoleCards();
				break;
			case ActionRequired:
				actionRequired();
				break;
			case PlayerFold:
				eventPlayerFold();
				break;
			case PlayerCall:
				eventPlayerCall();
				break;
			case PlayerRaise:
				eventPlayerRaise();
				break;
			case PlayerDiscConn:
				eventPlayerDiscConn();
				break;
			case NewHand:
				eventNewHand();
				break;
			case NewGame:
				eventNewGame();
				break;
			case EndHand:
				this.handState = HandState.WAITING;
				eventEndHand();
				break;
			case Flop:
				this.handState = HandState.FLOP;
				eventFlop();
				break;
			case Turn:
				this.handState = HandState.TURN;
				eventTurn();
				break;
			case River:
				this.handState = HandState.RIVER;
				eventRiver();
				break;
		}
	}
	
	/**
	 * An action is required by the client, they must respond within
	 * the set amount of turn time or else the server will move to the next
	 * player. This method will call the appropriate action required method
	 * depending on the hand state, that being preflop, flop, turn or river to help
	 * seperate the logic for each state.
	 */
	private void actionRequired(){
		switch(handState){
			case PREFLOP:
				this.actionRequiredPreflop();
				break;
			case FLOP:
				this.actionRequiredFlop();
				break;
			case TURN:
				this.actionRequiredTurn();
				break;
			case RIVER:
				this.actionRequiredRiver();
				break;
			default:
				//error !
				break;
		}
	}

	
	
	
	//---------------------------------------------------------
	//--- Implement these methods for the AI logic. 
	//---------------------------------------------------------
	protected abstract void actionRequiredPreflop();
	protected abstract void actionRequiredFlop();
	protected abstract void actionRequiredTurn();
	protected abstract void actionRequiredRiver();
	
	
	//---------------------------------------------------------
	//--- These are optional methods to implement. An event will be sent 
	//--- and the AI may choose to do processing as the game state has changed
	//--- in some way.
	//---------------------------------------------------------
	protected abstract void eventPlayerDiscConn();
	protected abstract void eventFlop();
	protected abstract void eventTurn();
	protected abstract void eventRiver();
	protected abstract void eventNewGame();
	protected abstract void eventNewHand();
	protected abstract void eventEndHand();
	protected abstract void eventPlayerFold();
	protected abstract void eventPlayerCall();
	protected abstract void eventPlayerRaise();
	protected abstract void eventOrderUpdate();	
	protected abstract void eventBlindUpdate();	
	protected abstract void eventDealtHoleCards();
	
}

